package com.threeti.mecool.shared.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public abstract class AbstractTreeNode<T> implements Serializable {

    private T id;

    private String name;

    private AbstractTreeNode<T> parent;

    private List<AbstractTreeNode<T>> childs = new ArrayList<AbstractTreeNode<T>>();

    public AbstractTreeNode(T id, String name) {
        super();
        this.id = id;
        this.name = name;
    }

    public T getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public AbstractTreeNode<T> getParent() {
        return parent;
    }

    public void setParent(AbstractTreeNode<T> parent) {
        this.parent = parent;
    }

    public List<AbstractTreeNode<T>> getChilds() {
        return Collections.unmodifiableList(childs);
    }

    public AbstractTreeNode<T> addChild(AbstractTreeNode<T> node) {
        node.setParent(this);
        childs.add(node);
        return this;
    }

    protected AbstractTreeNode() {
    }

    protected void setName(String name) {//jay:should only open for getter/setter reflection injection
        this.name = name;
    }

}
